using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MailClient
{
    public partial class DavyMail : Form
    {
        
        public DavyMail()
        {
            InitializeComponent();
            

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                System.IO.StreamReader re = System.IO.File.OpenText("settings.dat");
                String strSmtp = re.ReadLine();
                re.Close();

                txtSmtpserver.Text = strSmtp;
                
            }
            catch (Exception)
            {
                Form setting = new Settings(this, txtSmtpserver);
                setting.Show();
            }
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            pgbProgress.Enabled = true;
            pgbProgress.Visible = true;
            SmtpService smtpService = new SmtpService();
            smtpService.StrTo = txtTo.Text;
            smtpService.StrFrom = txtFrom.Text;
            smtpService.StrFromname = txtFromname.Text;
            smtpService.StrSubject = txtSubject.Text;
            smtpService.StrSmtpserver = txtSmtpserver.Text;
            smtpService.StrBody = rtbMail.Text; 
            String status = smtpService.SendMail();
            if(status.Equals("Mail succesfully sent!"))
            {
                this.ResetFields();
            }
            MessageBox.Show(status);
            pgbProgress.Enabled = false;
            pgbProgress.Visible = false;
        }
        private void ResetFields()
        {
            txtFrom.Text = "";
            txtFromname.Text = "";
            txtSubject.Text = "";
            txtTo.Text = "";
            rtbMail.Text = "";
        }

        private void mailServerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Settings s = new Settings(this, txtSmtpserver);
            s.Show();
        }
    }
}